package org.compiere.process;

import java.math.BigDecimal;
import java.sql.Timestamp;
import org.compiere.model.MhrmbonusLine;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import extend.org.compiere.hrm.TaxCompute;
import extend.org.compiere.hrm.TaxVariable;
import extend.org.compiere.hrm.TypePayment;

public class GenerateBonusLineSalary extends SvrProcess {

	private MhrmbonusLine hrmbl = null;
	private TaxVariable taxcomp = null;
	Timestamp dateFrom = null;
	double SUM = .0;

	@Override
	protected void prepare() {
		hrmbl = new MhrmbonusLine(getCtx(), getRecord_ID(), null);
	}

	@Override
	protected String doIt() throws Exception {
		
		dateFrom = hrmbl.getDateFrom();
		SUM = hrmbl.gethrm_amountbonus().doubleValue();
		/** Generate employee tax */
		taxcomp =  TaxCompute.GetTax(hrmbl.getC_BPartner_ID(), SUM, dateFrom, TypePayment.BONUS);
		
		//
		hrmbl.sethrm_OPV(new BigDecimal(taxcomp.getOPV()));
	    hrmbl.sethrm_IPN(new BigDecimal(taxcomp.getIPN()));
	    hrmbl.sethrm_COtch(new BigDecimal(taxcomp.getCOTCH()));
	    hrmbl.sethrm_CNalog(new BigDecimal(taxcomp.getCNALOG()));
	    hrmbl.sethrm_total(new BigDecimal(taxcomp.getTOTAL()));
	    hrmbl.saveEx();	   					    

	return Msg.translate(Env.getCtx(), "Success");
	}
}
